/*
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 *
 * Contributors: Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.api.internal;

/**
 * Wrapper class for Perforce API Spec class.
 *
 * @version $Revision: 491 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net>Boris
 *         Pruessmann</a>
 */
public final class Spec {

  /**
   * Used to store the native reference. <br>
   * DON'T TOUCH THE CONTENT OF THIS VARIABLE
   */
  @SuppressWarnings("unused")
  private int _nativeHandle;

  /** Constructor for Spec. */
  public Spec() {
    construct();
  }

  @Override
  public void finalize() throws Throwable {
    // TODO: Manually destruct
    super.finalize();
    destruct();
  }

  /**
   * Wrapper for Spec::Decode. decode a spec definition from a string.
   *
   * @param specDefString string to decode.
   * @param error error object to be used in case of an error.
   */
  public native void decode(String specDefString, Error error);

  /**
   * Wrapper for Spec::Format. turn SpecData into a spec string.
   *
   * @param data SpecData to format.
   * @return the formatted SpecData.
   */
  public native String format(SpecData data);

  /**
   * Wrapper for Spec::Parse. parse a spec string into SpecData.
   *
   * @param specString specification to use.
   * @param data SpecData that will contain the parsed specString.
   * @param error error object to be used in case of an error.
   * @param valid 1 if specStrig should be validated.
   */
  public native void parse(String specString, SpecData data, Error error, int valid);

  /**
   * Called by the constructor to initialize the native side of this class.
   */
  private native void construct();

  /**
   * Called by finalize() to destroy the native side of this class.
   */
  private native void destruct();
}
